#include <sqlite3.h>
#include "../include/ddebug.h"
#include <stdlib.h>
int main()
{
	sqlite3 *db;
	unsigned char buffer[20] = {0x09,0x01,0x02,0x03,0x00,0x00,0x02,0x34,0x31};
	unsigned char buffer2[20] = {0};
	if(sqlite3_open("/home/linux/ARM/rootfs/www/cgi-bin/warehouse.db",&db) != SQLITE_OK)
	{
		DDEBUG(P_URGENCY,"error:%s\n",sqlite3_errmsg(db));
		return -1;
	}
	char buf[100] = {0};
#if 0
	sprintf(buf, "update mytestss set no=no+1 where id = \'%s\'",buffer);
#else
	sprintf(buf, "select no from mytestss where id = \'%s\'",buffer);
//	sprintf(buf, "insert into mytestss values(1,\'%s\')",buffer);
#endif
	DDEBUG(P_NORMAL,"%s\n",buf);
	char *errmsg, **resultp;
	int nrow, ncolumn, i,j,index;

	if(sqlite3_get_table(db, buf, &resultp, &nrow, &ncolumn, &errmsg) != SQLITE_OK)
	{
		printf("error:%s\n",errmsg);
		return -2;
	}
	index = ncolumn;
	for(i = 0; i < nrow; i++)
	{
		for(j = 0; j < ncolumn; j++)
			printf("%s:%s\n",resultp[j],resultp[index++]);
	}
	printf("row:%d,column:%d\n",nrow, ncolumn);

#if 0
	int aaa;
	aaa = sqlite3_prepare(db,"select no from mytestss where id=5",-1,&stmt,0);
	printf("re:%d\n",aaa);
	aaa = sqlite3_step(stmt);
	printf("re:%d\n",aaa);
	printf("good\n");
	bufs = (char *)sqlite3_column_blob(stmt,0);
	if(bufs)
		memcpy(buffer2,bufs,20);
	iLen = sqlite3_column_bytes(stmt,0);
	
	printf("iLen:%d\n",iLen);
	iLen = 20;
	while(--iLen)
	{
		printf("%02x",buffer2[19-iLen]);
	}
#endif
//	DDEBUG(P_URGENCY,"row:%d,column:%d\n",nrow, ncolumn);


	return 0;
}
